package _go

func maxProfit(prices []int) int {
	min := 1000000
	max := 0

	for i := 0; i < len(prices); i++ {
		if min > prices[i] {
			min = prices[i] //找到最小值
		}
		if prices[i]-min > max {
			max = prices[i] - min //计算最大值 并记录
		}
	}
	return max
}
